<?php

namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Request;

class Mess extends Controller
{

    public function index()
    {
        $data = Db('msg')->select();
        return view('msg/msg', [
            'title' => '消息管理',
            'data' => $data,
        ]);
    }

    public function delete(Request $request)
    {
        $id = $request->param();
        $res = db('msg')->where('id', $id['id'])->delete();
        if ($res) {
            $this->redirect('admin/Mess/index');
        } else {
            $this->redirect('admin/Mess/index');

        }


    }

    public  function insert(Request $request)
    {
       $data = $request->post();
       $res = [
           'sysmsg'=>$data['mes']
       ];
       $result = db('msg')->insert($res);
       if($result){
           $info['status'] = true;
           $info['info'] = '系统消息发送成功';
       }else{
           $info['status'] = false;
           $info['info'] = '系统消息发送失败';
       }

       return json($info);
    }


}
